package cn.iocoder.yudao.module.system.service.scoreassignment;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.system.controller.admin.scoreassignment.vo.*;
import cn.iocoder.yudao.module.system.dal.dataobject.scoreassignment.ScoreAssignmentRuleDO;

import javax.validation.Valid;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.List;

/**
 * 赋分计算 Service 接口
 *
 * @author 芋道源码
 */
public interface ScoreAssignmentService {

    /**
     * 创建赋分规则
     *
     * @param createReqVO 创建信息
     * @return 编号
     */
    Long createScoreAssignmentRule(@Valid ScoreAssignmentRuleCreateReqVO createReqVO);

    /**
     * 更新赋分规则
     *
     * @param updateReqVO 更新信息
     */
    void updateScoreAssignmentRule(@Valid ScoreAssignmentRuleUpdateReqVO updateReqVO);

    /**
     * 删除赋分规则
     *
     * @param id 编号
     */
    void deleteScoreAssignmentRule(Long id);

    /**
     * 获得赋分规则
     *
     * @param id 编号
     * @return 赋分规则
     */
    ScoreAssignmentRuleDO getScoreAssignmentRule(Long id);

    /**
     * 获得赋分规则列表
     *
     * @param ids 编号
     * @return 赋分规则列表
     */
    List<ScoreAssignmentRuleDO> getScoreAssignmentRuleList(Collection<Long> ids);

    /**
     * 获得赋分规则分页
     *
     * @param pageReqVO 分页查询
     * @return 赋分规则分页
     */
    PageResult<ScoreAssignmentRuleDO> getScoreAssignmentRulePage(ScoreAssignmentRulePageReqVO pageReqVO);

    /**
     * 获得赋分规则列表, 用于 Excel 导出
     *
     * @param exportReqVO 查询条件
     * @return 赋分规则列表
     */
    List<ScoreAssignmentRuleDO> getScoreAssignmentRuleList(ScoreAssignmentRulePageReqVO exportReqVO);

    /**
     * 计算赋分
     *
     * @param subjectName 科目名称
     * @param originalScore 原始分
     * @param allScores 所有学生该科目的原始分列表
     * @return 赋分结果
     */
    ScoreAssignmentResult calculateAssignedScore(String subjectName, BigDecimal originalScore, List<BigDecimal> allScores);

    /**
     * 批量计算赋分
     *
     * @param subjectName 科目名称
     * @param scoreList 原始分列表
     * @return 赋分结果列表
     */
    List<ScoreAssignmentResult> batchCalculateAssignedScore(String subjectName, List<BigDecimal> scoreList);

    /**
     * 根据百分比计算赋分
     *
     * @param subjectName 科目名称
     * @param percentage 百分比（0-100）
     * @return 赋分结果
     */
    ScoreAssignmentResult calculateAssignedScoreByPercentage(String subjectName, Double percentage);

    /**
     * 获取科目的赋分规则
     *
     * @param subjectName 科目名称
     * @return 赋分规则列表
     */
    List<ScoreAssignmentRuleDO> getSubjectAssignmentRules(String subjectName);

    /**
     * 验证赋分规则的完整性
     *
     * @param subjectName 科目名称
     * @return 验证结果
     */
    AssignmentRuleValidationResult validateAssignmentRules(String subjectName);

    /**
     * 创建默认赋分规则
     *
     * @param ruleName 规则名称
     * @param subjectNames 科目名称列表
     */
    void createDefaultAssignmentRules(String ruleName, List<String> subjectNames);

    /**
     * 更新赋分规则状态
     *
     * @param id 编号
     * @param status 状态
     */
    void updateRuleStatus(Long id, Integer status);

    /**
     * 赋分结果
     */
    class ScoreAssignmentResult {
        private BigDecimal assignedScore;
        private String gradeLevel;
        private Double percentage;
        private String description;
        private boolean success;
        private String errorMessage;
        
        // 构造函数
        public ScoreAssignmentResult() {}
        
        public ScoreAssignmentResult(BigDecimal assignedScore, String gradeLevel, 
                                   Double percentage, String description) {
            this.assignedScore = assignedScore;
            this.gradeLevel = gradeLevel;
            this.percentage = percentage;
            this.description = description;
            this.success = true;
        }
        
        public ScoreAssignmentResult(String errorMessage) {
            this.success = false;
            this.errorMessage = errorMessage;
        }
        
        // Getters and Setters
        public BigDecimal getAssignedScore() { return assignedScore; }
        public void setAssignedScore(BigDecimal assignedScore) { this.assignedScore = assignedScore; }
        
        public String getGradeLevel() { return gradeLevel; }
        public void setGradeLevel(String gradeLevel) { this.gradeLevel = gradeLevel; }
        
        public Double getPercentage() { return percentage; }
        public void setPercentage(Double percentage) { this.percentage = percentage; }
        
        public String getDescription() { return description; }
        public void setDescription(String description) { this.description = description; }
        
        public boolean isSuccess() { return success; }
        public void setSuccess(boolean success) { this.success = success; }
        
        public String getErrorMessage() { return errorMessage; }
        public void setErrorMessage(String errorMessage) { this.errorMessage = errorMessage; }
    }

    /**
     * 赋分规则验证结果
     */
    class AssignmentRuleValidationResult {
        private boolean valid;
        private List<String> errorMessages;
        private List<String> warningMessages;
        private boolean hasGaps;
        private boolean hasOverlaps;
        
        // 构造函数
        public AssignmentRuleValidationResult() {}
        
        public AssignmentRuleValidationResult(boolean valid, List<String> errorMessages, 
                                            List<String> warningMessages, boolean hasGaps, boolean hasOverlaps) {
            this.valid = valid;
            this.errorMessages = errorMessages;
            this.warningMessages = warningMessages;
            this.hasGaps = hasGaps;
            this.hasOverlaps = hasOverlaps;
        }
        
        // Getters and Setters
        public boolean isValid() { return valid; }
        public void setValid(boolean valid) { this.valid = valid; }
        
        public List<String> getErrorMessages() { return errorMessages; }
        public void setErrorMessages(List<String> errorMessages) { this.errorMessages = errorMessages; }
        
        public List<String> getWarningMessages() { return warningMessages; }
        public void setWarningMessages(List<String> warningMessages) { this.warningMessages = warningMessages; }
        
        public boolean isHasGaps() { return hasGaps; }
        public void setHasGaps(boolean hasGaps) { this.hasGaps = hasGaps; }
        
        public boolean isHasOverlaps() { return hasOverlaps; }
        public void setHasOverlaps(boolean hasOverlaps) { this.hasOverlaps = hasOverlaps; }
    }

}